<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="/assets/css/project.css">
    <script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<style>

</style>
<body>
<div style="height: 50px; background-color: #0a5ba6;width: 100%;color: #FFFFFF">
    <div class="header-text">
        <div style="padding-top: 18px;float: right;padding-left: 75px;width: 80%;">商品订购</div>
    </div>
</div>
<!--<div id="slidershow"-->
<!--     class="carousel slide"-->
<!--     data-ride="carousel"-->
<!--     data-pause="hover"-->
<!--     data-wrap="true"-->
<!--     data-interval="5000"-->
<!--     data-auto="true"-->
<!--     style="width: 100%;height: 100%;margin-top:2px; "-->
<!--    <div class="carousel-inner" style="border-radius: 5px">-->
<!--        <div class="item active">-->
<!--            <a href="##"><img width="100%" src="/assets/img/cart1.jpg" alt=""></a>-->
<!--        </div>-->
<!--        <div class="item">-->
<!--            <a href="##"><img width="100%" src="/assets/img/cart2.jpg" alt=""></a>-->
<!--        </div>-->
<!--        <div class="item">-->
<!--            <a href="##"><img width="100%" src="/assets/img/cart3.jpg" alt=""></a>-->
<!--        </div>-->
<!--    </div>-->
<!--</div>-->
<div class="row">
    <div class="project-title">
        <span class="project-title-border">&nbsp;</span>
        <span class="project-title-text">商品列表</span>
    </div>
    <div class="project-list">
        <ul class="row list-u">
            {volist name="list" id="vo"}
            <li class="list-l">
                <img src="{$vo.thumbimage}" alt="" class="list-img">
                <div class="list-name">
                    {$vo.title}
                </div>
                <div class="list-name">
                    <span class="badge">{$vo.specs}</span>
                    <span class="badge" style="background: red">￥{$vo.price}</span>
                </div>
                <div class="list-name">
                    <a href="javascript:;" onclick="showCart(this)" data-price="{$vo.price}" data-id="{$vo.id}" class="btn btn-info">加购</a>
                </div>
            </li>
            {/volist}
        </ul>
    </div>
    <script>

    </script>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">订购信息</h4>
            </div>
            <div class="modal-body">
                订购数量：<input type="text" id="number" class="form-control" onblur="countMoney()">
                <input type="hidden" id="tips" value="0">
                商品单价：<input type="text" id="price" value="0" disabled class="form-control">
                商品总价：<input type="text" id="money" value="0" disabled class="form-control">
                <input type="hidden" id="goods_id" value="0">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="submitForm()">提交</button>
            </div>
        </div>
    </div>
</div>
<script>

    function showCart(goods){
        $('#myModal').modal('toggle');
        var goods_id=$(goods).data('id');
        $('#goods_id').val(goods_id);
        var price=$(goods).data('price');
        $('#price').val(price);
        $('#money').val(0)
        $('#tips').val(0);
        $('#number').val(0)
    }
    function countMoney()
    {
        var number=parseInt($('#number').val());
        var price=parseFloat($('#price').val())
        var money=number*price;
        $('#money').val(money)
    }
    function submitForm() {
        var number=$('#number').val();
        var money=$('#money').val();
        var price=$('#price').val();
        var goods_id=$('#goods_id').val();
        var tips=$('#tips').val();
        if(number>100 && tips==0){
            alert("请确认订购数量无误");
            $('#tips').val(1);
            return false;
        }
        $.ajax({
            url:"{:url('order/addCart')}",
            type:"POST",
            data:{number:number,money:money,goods_id:goods_id,price:price},
            success:function (){
                if(confirm("加购成功，是否去购物车结算。")){
                    window.location.href="{:url('user/cart')}";
                }else{
                    return false;
                }
            }
        })
    }
</script>
</body>
</html>